const replyList = new buildPage({
    name: 'replyList',
    template: `
        <div>
            <div i-if="replylist.length > 0">
                <div i-for="reply in replylist">
                    <div class="layui-panel" style="padding: 20px; margin-bottom: 20px; margin-top: 20px">
                        <div>
                            <img class="reply-avatar" :src="/cms/api/community/tool/get_file/{{ reply.avatar }}" alt="用户头像" />
                            <span class="reply-nick-name">
                                {{ reply.nick_name }}
                                <span i-if="reply.uid === userinfo.uid" class="layui-badge layui-bg-blue">本账户</span>
                                <span style="float: right; font-size: 12px;">{{ reply.update_time }}</span>
                            </span>
                            <p class="reply-signature">{{ reply.signature }}</p>
                        </div>
                        <div style="margin-top: 32px; margin-left: 62px;">
                            {{ reply.reply }}
                            <replyList i-if="reply.children.length > 0" props-replyList="reply.children" props-userInfo="userinfo"></replyList>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-panel" style="padding: 20px; margin-bottom: 20px" i-else>
                <span>暂无评论</span>
            </div>
        </div>
    `,
    data: {}
})

const components = {
    replyList
}


const Content = new buildPage({
    dom: '#contentReply',
    data: {
        replyList: [],
        userInfo: {}
    },
    components,
    created() {
        this.options.methods.getReplyList.apply(this)
        this.StateX.getAction('getUserInfo', 'userInfo').then(info => {
            Reflect.set(this.data, 'userInfo', info)
        })
    },
    methods: {
        getReplyList() {
            getReply({
                form_id: formId,
                id: id
            }).then(res => {
                if (res.code !== 200) return
                Reflect.set(this.data, 'replyList', res.items)
            })
        }
    }
}).use({
    stateX
}).mount()
